#!/usr/bin/env python
# coding: utf-8
#####插件说明#####
# 自动根据关键词回复
import json
import web
import re
import os


def run(WXBOT, msg, plugin_name):
    try:
        WXBOT.bot_conf[plugin_name]
    except:
        WXBOT.bot_conf[plugin_name] = {
            'switch': False,  # 自动发消息功能开关
            'black_keys': [u'恶意关键词'],  # 恶意关键词匹配
            'max_text_length': 80000,  # 消息允许的最大长度
            'keyword_list': [u'测试1', u'测试2', u'测试3'],
            'reply_list': {
                u'测试1': u'这是1',
                u'测试2': u'这是2',
                u'测试3': u'这是3'
            }
        }
        return

    if WXBOT.bot_conf[plugin_name]['switch'] == True and (msg['msg_type_id'] == 3 and msg['content']['type'] == 0):
        for x in WXBOT.bot_conf[plugin_name]['keyword_list']:
            if msg['content']['data'].find(x) >= 0:
                # 找到消息,拼接消息并群内通知
                send_message = u'%s!' % (WXBOT.bot_conf[plugin_name]['reply_list'][x])
                WXBOT.send_msg_by_uid(send_message, msg['user']['id'])
                # 打印输出发送日志
                print u'[INFO] s测试消息发送成功，%s---->%s\n%s' % (
                    msg['user']['name'], msg['content']['user']['name'], msg['content']['data'])
